import { Toast } from 'antd-mobile'
import { E } from '../../../constants'
import { getLocale } from 'umi';



// export function GetRequest(url) {
//     let index;
//     if (url.indexOf("?") != -1) {
//         let str = url.split("?")[1]
//         index = str.split("=")[1]
//     }

//     return index;
// }

export function GetRandomCard() {
    return Math.round(Math.random() * 5)
}

export function getCookie(cookiename) {
    var name = cookiename + "=";
    var cs = document.cookie.split(';');
    for (var i = 0; i < cs.length; i++) {
        var c = cs[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
}

export function GetRequest() {
    let url = window.location.search; //获取url中"?"符后的字串
    let theRequest = new Object();
    if (url.indexOf("?") != -1) {
        let str = url.substr(1);
        let strs = str.split("&");
        for (let i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

export function GetFirstImg(value) {
    if (value) {
        return value.split(',') && (value.split(','))[0]
    }
}
export function GetImgs(value) {
    if (value) {
        let data = value.split(',') && (value.split(','))
        data = data.filter((item) => {
            return item.indexOf('.mp4') < 0
        })
        if (data.length > 0) {
            let dd = data.map((item) => {
                let url = E.attchmentPrefix + item
                return {
                    img: url
                }
            })
            // console.log(dd, 'ddd')
            return dd
        }
        return []
    }
}
export function GetStringImgUrl(str) {
    // let url = str.i
    let regExp = /<img.+?\/>/g
    let res = str.match(regExp)
    return res
}
export function GetVideoUrl(str) {
    let regExp = /\/uploads.+?mp4/
    return str.match(regExp)
}
export function GetStringText(str) {
    return str.replace(/[^\u4e00-\u9fa5]/gi, "")
}

export function CreateLoading() {
  Toast.loading(getLocale() == "zh-CN" ? '加载中' : 'loading', 0)

    // return setTimeout(() => { Toast.loading(getLocale() == "zh-CN" ? '加载中' : 'loading', 0) }, 500)
}


